package com.banzhi.shop.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.banzhi.shop.R;
import com.banzhi.shop.adapter.HomeFrgAda;
import com.banzhi.shop.base.BaseActivity;
import com.banzhi.shop.fragment.DiscountCoponFrg;
import com.banzhi.shop.utils.TabLayoutUtil;
import com.banzhi.shop.utils.Translucent;

import java.util.ArrayList;
import java.util.List;

/**
 * 优惠券
 */
public class DiscountCouponActivity extends BaseActivity implements View.OnClickListener {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private ImageView ivback;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_discount_coupon);
        Translucent.setTranslucent(this);
        setinits();
        setListeners();
        setViews();
    }

    @Override
    protected void onStart() {
        super.onStart();
        tabLayout.post(new Runnable() {
            @Override
            public void run() {
                TabLayoutUtil.setIndicator(tabLayout, 20, 20);
            }
        });
    }

    private void setinits() {
        ivback = (ImageView)findViewById(R.id.iv_back);
        tabLayout = (TabLayout) findViewById(R.id.tabLayout);
        viewPager = (ViewPager) findViewById(R.id.viewpager);
        viewPager.setOffscreenPageLimit(3);

    }

    private void setViews() {
        List<Fragment> fragmentlist = new ArrayList<>();
        for (int i = 1; i < 4; i++) {
            DiscountCoponFrg frg = new DiscountCoponFrg().newInstance(i + "");
            fragmentlist.add(frg);
        }
        List<String> list_title = new ArrayList<>();
        list_title.add("未使用");
        list_title.add("已使用");
        list_title.add("已过期");

        HomeFrgAda hfadapter = new HomeFrgAda(getSupportFragmentManager(), fragmentlist, list_title);
        viewPager.setAdapter(hfadapter);
        //将tabLayout与viewpager连起来
        tabLayout.setupWithViewPager(viewPager);
    }

    private void setListeners() {
        ivback.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
